package net.zzy.pbbot.plugin.daliyNews.api;

import lombok.extern.slf4j.Slf4j;
import net.lz1998.pbbot.bot.Bot;
import net.lz1998.pbbot.bot.BotPlugin;
import net.lz1998.pbbot.utils.Msg;
import net.zzy.pbbot.plugin.daliyNews.service.DaliyNewsService;
import onebot.OnebotEvent;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import static net.zzy.pbbot.finalfield.Command.DALIY_NEWS;

/**
 * @author zhuZhaoYang
 * @date 2021/9/23 23:44
 */
@Slf4j
@Component
public class DaliyNews extends BotPlugin {


    @Override
    public int onPrivateMessage(@NotNull Bot bot, @NotNull OnebotEvent.PrivateMessageEvent event) {
        String rawMessage = event.getRawMessage();
        if (rawMessage.startsWith(DALIY_NEWS)) {
            Msg msg = DaliyNewsService.getNewsImage();
            msg.sendToFriend(bot, event.getUserId());
        }
        return MESSAGE_IGNORE;
    }

    @Override
    public int onGroupMessage(@NotNull Bot bot, @NotNull OnebotEvent.GroupMessageEvent event) {
        if (event.getRawMessage().startsWith(DALIY_NEWS)) {
            Msg msg = DaliyNewsService.getNewsImage();
            msg.sendToGroup(bot, event.getGroupId());
        }
        return MESSAGE_IGNORE;
    }


}
